<template>
  <a-popover placement="bottomRight">
    <span class="ant-pro-account-avatar">
      <a-icon type="bell" class="header-setting"></a-icon>
    </span>
    <template slot="content">
      <div class="notific-list">
        <div class="list-wrap">
          <a-list item-layout="horizontal" :data-source="data">
            <a-list-item slot="renderItem" slot-scope="item">
              <a-list-item-meta>
                <div slot="title" class="item-title">
                  <span>{{ item.title }}</span>
                  <span class="time">{{ item.time }}</span>
                </div>
                <div slot="description">{{ item.content }}</div>
              </a-list-item-meta>
            </a-list-item>
          </a-list>
        </div>
      </div>
    </template>
    <template slot="title">
      <div class="notific-title">
        <span>消息列表</span>
        <a>查看全部</a>
      </div>
    </template>
  </a-popover>
</template>

<script>
import { mapState } from 'vuex'
const data = [
  // {
  //   title: '系统通知',
  //   time: '2002-11-15',
  //   content: '这是一段很长很长的详情描述'
  // },
  // {
  //   title: '系统通知',
  //   time: '2002-11-15',
  //   content: '这是一段很长很长的详情描述'
  // },
  // {
  //   title: '系统通知',
  //   time: '2002-11-15',
  //   content: '这是一段很长很长的详情描述'
  // },
  // {
  //   title: '系统通知',
  //   time: '2002-11-15',
  //   content: '这是一段很长很长的详情描述'
  // }
]
export default {
  name: 'Notific',
  data () {
    return {
      data
    }
  },
  computed: {
    sseData () {
      return this.$store.getters.getSSEData
    },
    sseTimestamp () {
      return this.$store.getters.getSSETimestamp
    },
    ...mapState({ exchangeState: state => state.notification.exchangeState }),
    dynamicExchangeState () {
      return this.exchangeState
    }
  },
  watch: {
    exchangeState (newValue) {
      this.update()
    }
  },
  methods: {
    update () {
      const date = new Date(this.sseTimestamp)
      const day = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
      this.data.unshift({
        title: '系统通知',
        time: day,
        content: this.sseData
      })
    }
  }
}
</script>

<style scoped lang="less">
@import '../index.less';
.header-setting {
  font-size: 16px;
}
.notific-title {
  display: flex;
  justify-content: space-between;
  line-height: 42px;
  color: @heading-color;
  span {
    font-size: @font-size-lg;
    font-weight: 600;
  }
}
.notific-list {
  overflow: hidden;
  margin: -16px;
  width: 320px;
  height: 280px;
  .list-wrap {
    overflow: auto;
    padding: 0 24px;
    height: 100%;
  }
}
.item-title {
  display: flex;
  justify-content: space-between;
  font-weight: normal ;
}
</style>
